class Solution {
    public int longestOnes(int[] nums, int k) {
        int left=0,right=0,ret=0;
        int []a=new int[2];
        while(right<nums.length){
            a[nums[right]]++;
            while(a[0]>k){
                a[nums[left++]]--;
            }
            ret=Math.max(ret,right-left+1);
            right++;
        }
        return ret;
    }
}